package com.polytech.dao.hibernate;

import java.util.Collection;
import java.util.List;

import org.hibernate.Query;

import com.polytech.beans.Color;
import com.polytech.beans.Model;
import com.polytech.dao.BrandDao;
import com.polytech.dao.ModelDao;

public class ModelDaoHibernate extends AbstractHibernateDao implements ModelDao {

	public ModelDaoHibernate() {

	}

	@Override
	public void insert(Model model) {
		beginTransaction();
			session.save(model);
		commit();
		
	}

	@Override
	public Model select(String key) {
		beginTransaction();
			Model model=(Model)session.get(Model.class, key);
		commit();
		return model;
	}

	@Override
	public void remove(Model model) {
		beginTransaction();
			session.delete(model);
		commit();	
	}

	@Override
	public Collection<Model> selectAll() {
		List<Model> res=null;
		beginTransaction();
			res= (List<Model>) session.createQuery("from Model").list();
		commit();
		return res;
	}

}
